/*
 * Cursor.java
 * Created on July 28, 2007, 12:13 PM
 */

package view;

import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;

/**
 * @author Erol Hira
 */
public class Cursor extends Thread {
        
    private Color cursorColor;
    private Color bgColor;
    private Font font;
    private String cursor;
    private int delayTime;
    
    private boolean stop;
    
    private TextField textField;
    
    private int x;
    private int y;
    
    //------------------------------------------------------------------- 
    
    private int colorIndex;
    private Color color;
    
    //------------------------------------------------------------------- 
    
    
    public Cursor(TextField textField) {
        
        this.textField = textField;
        
        bgColor = Color.WHITE;
        
        cursorColor = Color.BLACK;
        cursor = "|";
        delayTime = 400;
        
    }
    
    public void run(){
        
        // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        if(true) return; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        
        while(stop == false){
            
            sleep();
            
            textField.setCursorNotified(true);
            textField.repaint();
        }
    }
    
    public void paintCursor(Graphics g){
        colorIndex++;
        colorIndex %= 2;

        color = colorIndex == 1 ? bgColor : cursorColor;
        
        GuiUtils.setColor(g, color);
        g.drawString(cursor, x, y, Graphics.TOP | Graphics.LEFT); // must be by font : Graphics.LEFT | Graphics.VCENTER;
    }
    
    private void sleep(){
        try {                
            sleep(delayTime);
        } catch (InterruptedException ex) {
            ex.printStackTrace();
            System.out.println("exc here");
        }
    }
    
    public void setCursor(String cursor){
        this.cursor = cursor;
    }        
    
    //-------------------------------------------------------------------     

    public Font getFont() {
        return font;
    }

    public void setFont(Font font) {
        this.font = font;
    }

    public Color getCursorColor() {
        return cursorColor;
    }

    public void setCursorColor(Color cursorColor) {
        this.cursorColor = cursorColor;
    }

    public Color getBgColor() {
        return bgColor;
    }

    public void setBgColor(Color bgColor) {
        this.bgColor = bgColor;
    }

    public String getCursor() {
        return cursor;
    }

    public int getDelayTime() {
        return delayTime;
    }

    public void setDelayTime(int delayTime) {
        this.delayTime = delayTime;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }
        
}
